from django.db import models


# Create your models here.

class Student(models.Model):
    SEX_CHOICES = {
        (0, '女'),
        (1, '男')
    }
    name = models.CharField(max_length=60, verbose_name='姓名')
    age = models.IntegerField(verbose_name='年龄', null=True, blank=True)
    sex = models.IntegerField(verbose_name='性别', null=True, blank=True, choices=SEX_CHOICES)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    classes = models.ForeignKey('Classes', on_delete=models.CASCADE)

    # 更改数据库中表名，与模型名不一样
    class Meta:
        db_table = 'student'

    # 重写模型类中的delete方法
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True  # 逻辑删除设为True
        self.save()


class Classes(models.Model):
    name = models.CharField(max_length=60, verbose_name='班级名称', help_text='班级名')
    slogan = models.TextField(verbose_name='口号', null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_time = models.DateTimeField(verbose_name='更新时间', auto_now=True)
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    def __str__(self):
        return self.name

    # 更改数据库中表名，与模型名不一样
    class Meta:
        db_table = 'classes'

    # 重写模型类中的delete方法
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True  # 逻辑删除设为True
        self.save()

